import 'package:flutter/material.dart';
import 'package:flutter_ui/pages/work_space_page.dart';
import 'package:flutter_ui/pages/patient_list_page.dart';
import 'package:flutter_ui/pages/profile_page.dart';
import 'package:flutter_ui/pages/task_list_page.dart';
import 'package:flutter_ui/widgets/custom_bottom_navigation_bar.dart';

/// 主导航页面，包含底部导航栏和各个子页面
class MainNavigation extends StatefulWidget {
  const MainNavigation({super.key});

  @override
  State<MainNavigation> createState() => _MainNavigationState();
}

class _MainNavigationState extends State<MainNavigation> {
  // 当前选中的页面索引
  int _currentIndex = 0; // 默认选中首页
  
  // 页面列表
  late final List<Widget> _pages;
  
  @override
  void initState() {
    super.initState();
    _pages = [
      const PatientListPage(), // 病人一览
      const WorkSpace(),        // 工作台
      const TaskListPage(),     // 任务列表
      const ProfilePage(),      // 我的
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: _pages,
      ),
      bottomNavigationBar: CustomBottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}